#!/usr/bin/env python
# -*-coding:UTF-8-*
################################################################################


import time
import random

class DBTools():
	
	def get_bit(self, m):
		"""
		Get a bit-field type.
		M indicates the number of bits per value, from 1 to 64.
		The default is 1 if M is omitted.
		"""
		
		pass
	
	def get_tinyint(self, m, sign = True):
		"""
		Get a very small integer.
		The signed range is -128 to 127.
		The unsigned range is 0 to 255.
		"""
		
		if (sign) : # signed
			return self.__rand(-128, 127)
		else :      # unsigned
			return self.__rand(0, 255)
	
	def get_bool(self):
		"""
		Get a bool value.
		A value of zero is considered false.
		Non-zero values are considered true.
		"""
		
		if random.randint(0, 255) % 2 == 0 :
			return "0"
		else :
			return "1"
	
	def get_boolean(self):
		"""
		Get a boolean value.
		boolean is same to bool in MySQL.
		"""
		
		return self.get_bool()
	
	def get_samllint(self, m, sign = True):
		"""
		Get a small integer.
		The signed range is -32768 to 32767.
		The unsigned range is 0 to 65535.
		"""
		
		if sign :
			return self.__rand(-32768, 32767)
		else :
			return self.__rand(0, 65535)
	
	def get_mediumint(self, m, sign = True):
		"""
		Get a medium-sized integer.
		The signed range is -8388608 to 8388607.
		The unsigned range is 0 to 16777215.
		"""
		
		if sign :
			return self.__rand(-8388608, 8388607)
		else :
			return self.__rand(0, 16777215)
	
	def get_int(self, m, sign = True):
		"""
		Get a normal-size integer.
		The signed range is -2147483648 to 2147483647.
		The unsigned range is 0 to 4294967295.
		"""
		
		if (sign) :
			return self.__rand(-2147483648, 2147483647)
		else :
			return self.__rand(0, 4294967295)
	
	def get_integer(self, m, sign):
		"""
		This type is a synonym for INT.
		"""
		
		return self.get_int(m, sign)
	
	def get_bigint(self, m, sign):
		"""
		Get a large integer.
		The signed range is -9223372036854775808 to 9223372036854775807.
		The unsigned range is 0 to 18446744073709551615.
		"""
		
		if (sign) :
			return self.__rand(-9223372036854775808, 9223372036854775807)
		else :
			return self.__rand(0, 18446744073709551615)
	
	def get_float(self, m, d):
		"""
		A small (single-precision) floating-point number.
		Allowable values are -3.402823466E+38 to -1.175494351E-38, 0, and
		1.175494351E-38 to 3.402823466E+38. These are the theoretical limits,
		based on the IEEE standard. The actual range might be slightly smaller
		depending on your hardware or operating system.
		
		M is the total number of digits and D is the number of digits following
		the decimal point. If M and D are omitted, values are stored to the
		limits allowed by the hardware. A single-precision floating-point
		number is accurate to approximately 7 decimal places.
		"""
		
		pass
	
	def get_double(self, m, d):
		"""
		A normal-size (double-precision) floating-point number.
		Allowable values are -1.7976931348623157E+308 to - 2.2250738585072014E-308,
		0, and 2.2250738585072014E-308 to 1.7976931348623157E+308. These are the
		theoretical limits, based on the IEEE standard. The actual range might
		be slightly smaller depending on your hardware or operating system.
		
		M is the total number of digits and D is the number of digits following
		the decimal point. If M and D are omitted, values are stored to the
		limits allowed by the hardware. A double-precision floating-point
		number is accurate to approximately 15 decimal places.
		"""
		
		pass
	
	def get_double_precision(self, m, d):
		"""
		These types are synonyms for DOUBLE.
		
		Exception:
			If the REAL_AS_FLOAT SQL mode is enabled, REAL is a synonym for
			FLOAT rather than DOUBLE.
		"""
		
		pass
	
	def get_float(self, p):
		"""
		A floating-point number. p represents the precision in bits, but MySQL
		uses this value only to determine whether to use FLOAT or DOUBLE for
		the resulting data type. If p is from 0 to 24, the data type becomes
		FLOAT with no M or D values. If p is from 25 to 53, the data type
		becomes DOUBLE with no M or D values. The range of the resulting column
		is the same as for the single-precision FLOAT or double-precision
		DOUBLE data types described earlier in this section.
		
		FLOAT(p) syntax is provided for ODBC compatibility.
		"""
		
		pass

	def get_decimal(self, m, d):
		"""
		A packed “exact” fixed-point number.
		M is the total number of digits (the precision) and D is the number of
		digits after the decimal point (the scale). The decimal point and
		(for negative numbers) the “-” sign are not counted in M. If D is 0,
		values have no decimal point or fractional part. The maximum number of
		digits (M) for DECIMAL is 65. The maximum number of supported
		decimals (D) is 30. If D is omitted, the default is 0. If M is omitted,
		the default is 10.
		"""
		
		pass
	
	def get_dec(self, m, d):
		"""
		These types are synonyms for DECIMAL.
		"""
		
		pass
	
	def get_numeric(self, m, d):
		"""
		These types are synonyms for DECIMAL.
		"""
		
		pass
	
	def get_fixed(self, m, d):
		"""
		The FIXED synonym is available for compatibility with
		other database systems.
		"""
		
		pass
	
	def get_date(self):
		"""
		A date. The supported range is '1000-01-01' to '9999-12-31'.
		
		MySQL displays DATE values in 'YYYY-MM-DD' format, but allows
		assignment of values to DATE columns using either strings or numbers.
		"""
		
		pass
	
	def get_datetime(self):
		"""
		A date and time combination.
		The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
	
		MySQL displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format,
		but allows assignment of values to DATETIME columns using either
		strings or numbers.
		"""
		
		pass

	def get_timestamp(self):
		"""
		A timestamp. The range is '1970-01-01 00:00:01' UTC to
		'2038-01-09 03:14:07' UTC. TIMESTAMP values are stored as the number
		of seconds since the epoch ('1970-01-01 00:00:00' UTC).
		
		A TIMESTAMP cannot represent the value '1970-01-01 00:00:00' because
		that is equivalent to 0 seconds from the epoch and the value 0 is
		reserved for representing '0000-00-00 00:00:00', the “zero”
		TIMESTAMP value.
		"""
		
		pass
	
	def get_time(self):
		"""
		A time. The range is '-838:59:59' to '838:59:59'.
		
		MySQL displays TIME values in 'HH:MM:SS' format, but allows assignment
		of values to TIME columns using either strings or numbers.
		"""
		
		pass
	
	def get_char(self, m = 1):
		"""
		A fixed-length string that is always right-padded with spaces to the
		specified length when stored. M represents the column length in
		characters. The range of M is 0 to 255.
		If M is omitted, the length is 1.
		"""
		
		pass
	
	def get_varchar(self, m):
		"""
		A variable-length string. M represents the maximum column length in
		characters. The range of M is 0 to 65,535. The effective maximum length
		of a VARCHAR is subject to the maximum row size (65,535 bytes, which is
		shared among all columns) and the character set used. For example,
		utf8 characters can require up to three bytes per character, so a
		VARCHAR column that uses the utf8 character set can be declared to be
		a maximum of 21,844 characters.
		
		MySQL stores VARCHAR values as a one-byte or two-byte length prefix
		plus data. The length prefix indicates the number of bytes in the value.
		A VARCHAR column uses one length byte if values require no more than
		255 bytes, two length bytes if values may require more than 255 bytes.
		"""
		pass
	
	def get_binary(self, m):
		"""
		The BINARY type is similar to the CHAR type, but stores binary byte
		strings rather than non-binary character strings. M represents the
		column length in bytes.
		"""
		
		pass
	
	def get_varbinary(self, m):
		"""
		The VARBINARY type is similar to the VARCHAR type, but stores binary
		byte strings rather than non-binary character strings. M represents the
		maximum column length in bytes.
		"""
		
		pass
	
	def get_tinyblob(self):
		"""
		A BLOB column with a maximum length of 255 (2^8 – 1) bytes. Each
		TINYBLOB value is stored using a one-byte length prefix that indicates
		the number of bytes in the value.
		"""
		
		pass
	
	def get_tinytext(self):
		"""
		A TEXT column with a maximum length of 255(2^8 – 1) characters.
		The effective maximum length is less if the value contains multi-byte
		characters. Each TINYTEXT value is stored using a one-byte length
		prefix that indicates the number of bytes in the value.
		"""
		
		pass
	
	def get_blob(self, m):
		"""
		A BLOB column with a maximum length of 65,535 (2^16 – 1) bytes. Each
		BLOB value is stored using a two-byte length prefix that indicates the
		number of bytes in the value.
		
		An optional length M can be given for this type. If this is done,
		MySQL creates the column as the smallest BLOB type large enough to
		hold values M bytes long.
		"""
		
		pass
	
	def get_text(self, m):
		"""
		A TEXT column with a maximum length of 65,535 (2^16 – 1) characters.
		The effective maximum length is less if the value contains multi-byte
		characters. Each TEXT value is stored using a two-byte length prefix
		that indicates the number of bytes in the value.
		
		An optional length M can be given for this type. If this is done,
		MySQL creates the column as the smallest TEXT type large enough to
		hold values M characters long.
		"""
		
		pass
	
	def get_mediumblob(self):
		"""
		A BLOB column with a maximum length of 16,777,215 (2^24 – 1) bytes.
		Each MEDIUMBLOB value is stored using a three-byte length prefix that
		indicates the number of bytes in the value.
		"""
		
		pass
	
	def get_mediumtext(self):
		"""
		A TEXT column with a maximum length of 16,777,215(2^24 – 1) characters.
		The effective maximum length is less if the value contains multi-byte
		characters. Each MEDIUMTEXT value is stored using a three-byte length
		prefix that indicates the number of bytes in the value.
		"""
		
		pass
	
	def get_longblob(self):
		"""
		A BLOB column with a maximum length of 4,294,967,295 or 4GB(2^32 – 1)
		bytes. The effective maximum length of LONGBLOB columns depends on the
		configured maximum packet size in the client/server protocol and
		available memory. Each LONGBLOB value is stored using a four-byte
		length prefix that indicates the number of bytes in the value.
		"""
		
		pass
	
	def get_longtext(self):
		"""
		A TEXT column with a maximum length of 4,294,967,295 or 4GB(2^32 – 1)
		characters. The effective maximum length is less if the value contains
		multi-byte characters. The effective maximum length of LONGTEXT columns
		also depends on the configured maximum packet size in the client/server
		protocol and available memory. Each LONGTEXT value is stored using
		a four-byte length prefix that indicates the number of bytes in
		the value.
		"""
		
		pass
	
	def get_enum(self, values):
		"""
		ENUM('value1','value2',...)
		
		An enumeration. A string object that can have only one value,
		chosen from the list of values 'value1', 'value2', ..., NULL or the
		special '' error value. An ENUM column can have a maximum of 65,535
		distinct values. ENUM values are represented internally as integers.
		"""
		
		pass
	
	def get_sets(self, values):
		"""
		SET('value1','value2',...)
		
		A set. A string object that can have zero or more values, each of
		which must be chosen from the list of values 'value1', 'value2', ...
		A SET column can have a maximum of 64 members. SET values are
		represented internally as integers.
		"""
		
		pass
	
	def __rand(self, star = 0, stop = 255):
		return str(random.randint(start, stop))
